﻿<Window x:Class="CYPlayer.PlaylistWindow" Name="PLWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:CYPlayer.ViewModel"
        Title="PlaylistWindow" Height="300" Width="225" WindowStyle="ToolWindow" Icon="/CYPlayer;component/appicon.ico"
        Topmost="False" ShowInTaskbar="False" Closing="PLWindow_Closing">
  <Window.Triggers>
    <EventTrigger RoutedEvent="Window.Loaded">
      <EventTrigger.Actions>
        <BeginStoryboard>
          <Storyboard>
            <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:1" />
          </Storyboard>
        </BeginStoryboard>
      </EventTrigger.Actions>
    </EventTrigger>
  </Window.Triggers>
  <Window.DataContext>
    <local:PlaylistWindowVM />
  </Window.DataContext>
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="*" />
      <RowDefinition Height="*" />
      <RowDefinition Height="6*" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Border Grid.Row="0" Background="Lavender">
      <TextBlock TextAlignment="Center" FontFamily="Segoe UI" FontSize="16">PlayList</TextBlock>
    </Border>
    <StackPanel Background="#11D8EE" Grid.Row="1" Orientation="Horizontal">
      <TextBlock FontFamily="Segoe UI" Foreground="Black" VerticalAlignment="Center" FontSize="15"
                 Margin="0,0,5,0" Height="25" Width="52">Name:</TextBlock>
      <TextBox Width="145" Background="#D6FAFE" Foreground="Black" BorderBrush="#63B5FF" FontFamily="Segoe UI"
               FontSize="14" VerticalAlignment="Center" Text="{Binding SelectedPlaylistName}"></TextBox>
    </StackPanel>
    <ListView Grid.Row="2" Foreground="White" Background="#B4BFF8" Width="Auto" Name="plbox"
              ItemsSource="{Binding Songs}" SelectedIndex="{Binding SelectedSongIndex}" SelectedItem="{Binding SelectedSong}"
              FontFamily="Segoe UI" FontSize="14">
      <ListView.ItemTemplate>

        <DataTemplate>
          <Grid ShowGridLines="True">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="90" />
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="90" />
            </Grid.ColumnDefinitions>
            <Label Grid.Column="0" Content="{Binding Title}" Foreground="MidnightBlue" FontSize="12"
                   Margin="0,0,10,0" />
            <Label Grid.Column="1" Content="-" Foreground="MidnightBlue" FontSize="13" />
            <Label Grid.Column="2" Content="{Binding Duration}" Foreground="MidnightBlue" FontSize="12"
                   Margin="10,0,0,0" />

          </Grid>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>
    <Popup Placement="Center" Name="PLPopup" Grid.Row="2" AllowsTransparency="True" PopupAnimation="Slide">
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="*" />
          <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Label Content="Playlists" Background="PaleGreen" BorderThickness="1" BorderBrush="Black" Grid.Row="0"
               Margin="0"></Label>
        <ListView ItemsSource="{Binding Playlists, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}" Grid.Row="1" SelectedItem="{Binding SelectedPlaylist}">
          <ListView.ItemTemplate>
            <DataTemplate>
              <Grid>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Label Content="{Binding PlaylistName}" Grid.Column="0"></Label>
                <Label Content="{Binding PlaylistSongsCount}" Grid.Column="1"></Label>
              </Grid>
            </DataTemplate>
          </ListView.ItemTemplate>
          <ListView.ContextMenu>
            <ContextMenu>
              <MenuItem Header="Delete" Style="{StaticResource MyMenuItem}"
                        Command="{Binding DeletePlaylist}">
              </MenuItem>
            </ContextMenu>
          </ListView.ContextMenu>
        </ListView>
      </Grid>
    </Popup>
    <StackPanel Grid.Row="3" Orientation="Horizontal" Background="Black">
      <Button Height="26" Width="30" VerticalAlignment="Center" Margin="5,0,5,0" Command="{Binding SavePlaylist}">
        <Image Source="save.png" Height="20" Width="32" HorizontalAlignment="Center" VerticalAlignment="Center"
               OpacityMask="Black"></Image>
      </Button>
      <Button Height="26" Width="30" VerticalAlignment="Center" Margin="5,0,5,0" Name="AddFile_btn"
              Command="{Binding AddSong}">
        <Canvas Height="20" Width="20">
          <Path Stroke="White" StrokeThickness="3" Data="M10,0 10,20 M0,10 20,10"></Path>
        </Canvas>
      </Button>
      <Button Height="26" Width="30" VerticalAlignment="Center" Margin="5,0,5,0" Name="deleteSong_btn"
              Command="{Binding DeleteSong}">
        <Canvas Height="20" Width="20">
          <Line X1="0" X2="20" Y1="10" Y2="10" Stroke="White" StrokeThickness="3"></Line>
        </Canvas>
      </Button>
      <Button Height="26" Width="30" VerticalAlignment="Center" Margin="5,0,5,0" Command="{Binding OpenPopup}"
              CommandParameter="{Binding ElementName=PLPopup}">
        <Canvas Height="20" Width="20">
          <Path Stroke="White" StrokeThickness="2" Fill="White">
            <Path.Data>
              <PathGeometry>
                <PathFigure IsClosed="True" StartPoint="3,13">
                  <PolyLineSegment Points="10,3 17,13"></PolyLineSegment>
                </PathFigure>
                <PathFigure StartPoint="0,17">
                  <LineSegment Point="20,17"></LineSegment>
                </PathFigure>
              </PathGeometry>
            </Path.Data>
          </Path>
        </Canvas>
      </Button>
      <Button Height="26" Width="30" VerticalAlignment="Center" Margin="5,0,5,0" Name="mediaLib_btn"
              Click="MediaLibBtnClick">
        <Path Stroke="White" HorizontalAlignment="Center" StrokeThickness="4"
              Data="M3,1 3,20 M8,0 8,20 M12,1 13,20 M16,2 21,20"></Path>
      </Button>
    </StackPanel>
  </Grid>
</Window>